package com.sylli.oeuf.server.game.logic.skill;

import java.util.ArrayList;
import java.util.Collection;

import com.sylli.oeuf.server.game.logic.ActionProduct;
import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.CastingTarget;
import com.sylli.oeuf.server.game.logic.EventParameter;
import com.sylli.oeuf.server.game.logic.Skill;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.ConsumeMana;
import com.sylli.oeuf.server.game.logic.action.Damage;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueElement;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueFlag;
import com.sylli.oeuf.server.game.logic.invocation.EnoughMPInvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationAction;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEntry;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;

public class Exorcist_WrathOfTheLiving extends Skill {

	public Exorcist_WrathOfTheLiving() {
		super("wrath of the living", CastingTarget.FocusTarget);
		getEntries().put(
				InvocationEvent.STD_IE_ON_ACTIVE,
				new InvocationEntry(
						new EnoughMPInvocationCondition() {

							@Override
							public int getAgainstValue(int rank) {
								return computeManaUse(rank);
							}
							
						},
						new InvocationAction() {
							@Override
							public Collection<ActionProduct> act(
									int rank, BattleActor caster,
									CastingTarget target,
									EventParameter ep) {

								Collection<ActionProduct> product = new ArrayList<ActionProduct>();
								
								float modifier = (float) (0.5 + (0.2 * (rank -1)));
								int dmgValue = (int) ((caster.getCurrMana() - computeManaUse(rank)) * modifier);
								
								 Damage damageProduct = new Damage(caster, 
										caster.getProperTarget(CastingTarget.FocusTarget),
										dmgValue,
										ActionValueFlag.Normal,
										ActionValueElement.Arcane);
								
								product.add(damageProduct);
								product.add(new ConsumeMana(caster, 
										caster.getProperTarget(target),
										caster.getCurrMana()));
								product.add(new CombatLog(caster, caster.getProperTarget(CastingTarget.FocusTarget),
										caster.getName() + " cast [" + name + "] on " + caster.getProperTarget(CastingTarget.FocusTarget).getName() + " dealing %p.", 
										damageProduct));
								return product;
							}
						}));
		}
	
	private int computeManaUse(int rank) {
		return 5 * rank;
	}

}
